package gui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

public class PrimaryPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private GridBagLayout layout;
	private GridBagLayout partDetailLayout;
	private JButton saveButton;
	private PartsTree partsTree;
	
	private JPanel partDetailPanel;
	private JLabel partNameLabel;
	private JLabel partValueLabel;
	private JTextField partNameField;
	private JTextField partValueField;
	
	public PrimaryPanel() {
		init();
	}
	
	private void init() {
		partNameLabel = new JLabel("Part name");
		partNameField = new JTextField(20);
		partValueLabel = new JLabel("Part value");
		partValueField = new JTextField(10);
		saveButton = new JButton("Save changes");
		
		this.setBorder(new TitledBorder("Part Manager"));
		layout = new GridBagLayout();
		this.setLayout(layout);
		GridBagConstraints c = new GridBagConstraints();
		
		c.anchor = GridBagConstraints.FIRST_LINE_START;
		c.weighty = 1.0;
		c.weightx = 1.0;
		c.fill = GridBagConstraints.BOTH;
		partsTree = new PartsTree(partNameField, partValueField);
		layout.setConstraints(partsTree, c);
		this.add(partsTree);
		
		c.gridwidth = GridBagConstraints.REMAINDER;
		partDetailPanel = new JPanel();
		partDetailPanel.setBorder(new TitledBorder("Part Detail"));
		layout.setConstraints(partDetailPanel, c);
		this.add(partDetailPanel);
		
		partDetailLayout = new GridBagLayout();
		partDetailPanel.setLayout(partDetailLayout);
		c = new GridBagConstraints();
		
		c.anchor = GridBagConstraints.FIRST_LINE_START;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.weightx = 1.0;
		partDetailLayout.setConstraints(partNameLabel, c);
		partDetailPanel.add(partNameLabel);
		
		c.fill = GridBagConstraints.NONE;
		c.gridwidth = GridBagConstraints.REMAINDER;
		partDetailLayout.setConstraints(partNameField, c);
		partDetailPanel.add(partNameField);

		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridwidth = 1;
		partDetailLayout.setConstraints(partValueLabel, c);
		partDetailPanel.add(partValueLabel);
		
		c.fill = GridBagConstraints.NONE;
		saveButton = new JButton("Save changes");c.gridwidth = GridBagConstraints.REMAINDER;
		partDetailLayout.setConstraints(partValueField, c);
		partDetailPanel.add(partValueField);

		c.gridwidth = 1;
		c.weighty = 1.0;
		partDetailLayout.setConstraints(saveButton, c);
		partDetailPanel.add(saveButton);
	}
}
